/*
    Copyright 2006 Andrew Wilkinson <andrew@indiegigs.co.uk>

    This file is part of libgp2x.

    libgp2x is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    libgp2x is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with libgp2x; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef __LIB_GP2x_INTERNAL_H__
#define __LIB_GP2x_INTERNAL_H__

#include <sys/stat.h>
#include <fcntl.h>

#ifdef GP2x_940
#include "gp2x_940t.h"
#else
#include "gp2x.h"
#endif

void GP2x_video_init();
void GP2x_input_init();
void GP2x_message_init();
void GP2x_upper_memory_init(unsigned long base, unsigned long size);

void GP2x_940_setup();
void GP2x_940_shutdown();

extern unsigned char GP2x_940_running;

extern volatile unsigned short* GP2x_registers;

/* Below are the definitions for register locations.
 */
#define GP2x_register(reg) GP2x_registers[(reg)>>1]

#define GP2x_REG_940_CONTROL        (0x0904)
#define GP2x_REG_SCREEN_SYNC        (0x1182) /* GPIOB */
#define GP2x_REG_BUTTONS_1          (0x1184) /* GPIOC */
#define GP2x_REG_BUTTONS_2          (0x1186) /* GPIOC */
#define GP2x_REG_JOYSTICK           (0x1198)
#define GP2x_REG_BIT_DEPTH          (0x28DA)
#define GP2x_REG_LINE_WIDTH         (0x290C)
#define GP2x_REG_IMAGE_ADDRESS_ODD  (0x290E) /* MLC_STL_OADR */
#define GP2x_REG_IMAGE_ADDRESS_EVEN (0x2912) /* MLC_STL_EADR */
#define GP2x_REG_940_INTERRUPT_1    (0x3B40)
#define GP2x_REG_940_INTERRUPT_2    (0x3B42)
#define GP2x_REG_940_MEMORY_BASE    (0x3B48)

enum {
    GP2x_MESSAGE_SYNC = 1<<25,
    GP2x_MESSAGE_FPRINTF,
    GP2x_MESSAGE_FOPEN,
    GP2x_MESSAGE_FCLOSE,
    GP2x_MESSAGE_FSEEK,
    GP2x_MESSAGE_FTELL,
    GP2x_MESSAGE_FREAD,
    GP2x_MESSAGE_FWRITE,
    GP2x_MESSAGE_FLIP_UNSYNC,
    GP2x_MESSAGE_FLIP_SYNC,
    GP2x_MESSAGE_940_QUIT,
};

#ifdef HOST_PC
#include "pc/gp2x_internal.h"
#else
#include "gp2x/gp2x_internal.h"
#endif

extern unsigned char GP2x_940_control_screen;

#endif
